<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="" prop="exceptionOrderId">
        <el-input
          v-model.trim="queryParams.exceptionOrderId"
          placeholder="请输入异常主订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="exceptionSubOrderId">
        <el-input
          v-model.trim="queryParams.exceptionSubOrderId"
          placeholder="请输入异常子订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="channel">
        <el-select v-model="queryParams.channel" placeholder="渠道" clearable>
          <el-option
            v-for="dict in dict.type.sys_product_qudao"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="" prop="channel">
        <el-select
          v-model="queryParams.isRepaired"
          placeholder="是否修复"
          clearable
        >
          <el-option
            v-for="dict in dict.type.sys_is_fix"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="订单销售额" prop="orderSalesAmount">
        <el-input
          v-model.trim="queryParams.orderSalesAmount"
          placeholder="请输入订单销售额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="达播销售额" prop="talentSalesAmount">
        <el-input
          v-model.trim="queryParams.talentSalesAmount"
          placeholder="请输入达播销售额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单销售数量" prop="orderSalesQuantity">
        <el-input
          v-model.trim="queryParams.orderSalesQuantity"
          placeholder="请输入订单销售数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="达播销售数量" prop="talentSalesQuantity">
        <el-input
          v-model.trim="queryParams.talentSalesQuantity"
          placeholder="请输入达播销售数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否修复" prop="isRepaired">
        <el-input
          v-model.trim="queryParams.isRepaired"
          placeholder="请输入是否修复"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="逻辑删除" prop="isDelete">
        <el-input
          v-model.trim="queryParams.isDelete"
          placeholder="请输入逻辑删除"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="" prop="dataDate">
        <!-- <el-date-picker
          clearable
          v-model="queryParams.dataDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="支付日期"
        >
        </el-date-picker> -->
        <el-date-picker
          v-model="value2"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
          @change="changeTime"
          size="mini"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['live:BiAbnormalOrder:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['live:BiAbnormalOrder:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['live:BiAbnormalOrder:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['live:BiAbnormalOrder:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handlerecoverAbnormal"
          >异常订单恢复</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="BiAbnormalOrderList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="id" align="center" prop="id" /> -->

      <el-table-column label="异常描述" align="center" prop="abnormalLabel" />
      <el-table-column label="渠道" align="center" prop="channel" />
      <el-table-column
        label="异常主订单号"
        align="center"
        prop="exceptionOrderId"
      />
      <el-table-column
        label="异常子订单号"
        align="center"
        prop="exceptionSubOrderId"
      />
      <el-table-column
        label="订单销售额"
        align="center"
        prop="orderSalesAmount"
      />
      <el-table-column
        label="达播销售额"
        align="center"
        prop="talentSalesAmount"
      />
      <el-table-column
        label="订单销售数量"
        align="center"
        prop="orderSalesQuantity"
      />
      <el-table-column
        label="达播销售数量"
        align="center"
        prop="talentSalesQuantity"
      />
      <el-table-column label="支付日期" align="center" prop="dataDate" />
      <el-table-column label="是否修复" align="center" prop="isRepaired">
        <template slot-scope="scope">
          {{ scope.row.isRepaired | state1 }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="逻辑删除" align="center" prop="isDelete" /> -->
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['live:BiAbnormalOrder:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['live:BiAbnormalOrder:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改达播异常订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="异常主订单号" prop="exceptionOrderId">
          <el-input
            v-model.trim="form.exceptionOrderId"
            placeholder="请输入异常主订单号"
          />
        </el-form-item>
        <el-form-item label="异常子订单号" prop="exceptionSubOrderId">
          <el-input
            v-model.trim="form.exceptionSubOrderId"
            placeholder="请输入异常子订单号"
          />
        </el-form-item>
        <el-form-item label="订单销售额" prop="orderSalesAmount">
          <el-input
            v-model.trim="form.orderSalesAmount"
            placeholder="请输入订单销售额"
          />
        </el-form-item>
        <el-form-item label="达播销售额" prop="talentSalesAmount">
          <el-input
            v-model.trim="form.talentSalesAmount"
            placeholder="请输入达播销售额"
          />
        </el-form-item>
        <el-form-item label="订单销售数量" prop="orderSalesQuantity">
          <el-input
            v-model.trim="form.orderSalesQuantity"
            placeholder="请输入订单销售数量"
          />
        </el-form-item>
        <el-form-item label="达播销售数量" prop="talentSalesQuantity">
          <el-input
            v-model.trim="form.talentSalesQuantity"
            placeholder="请输入达播销售数量"
          />
        </el-form-item>
        <el-form-item label="是否修复" prop="isRepaired">
          <el-input
            v-model.trim="form.isRepaired"
            placeholder="请输入是否修复"
          />
        </el-form-item>
        <el-form-item label="逻辑删除" prop="isDelete">
          <el-input v-model.trim="form.isDelete" placeholder="请输入逻辑删除" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model.trim="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listBiAbnormalOrder,
  getBiAbnormalOrder,
  delBiAbnormalOrder,
  addBiAbnormalOrder,
  updateBiAbnormalOrder,
  recoverAbnormal,
} from "@/api/live/BiAbnormalOrder";
import moment from "moment";
export default {
  name: "BiAbnormalOrder",
  dicts: ["sys_product_qudao", "sys_is_fix"],
  data() {
    return {
      inputValue: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 达播异常订单表格数据
      BiAbnormalOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        exceptionOrderId: null,
        exceptionSubOrderId: null,
        orderSalesAmount: null,
        talentSalesAmount: null,
        orderSalesQuantity: null,
        talentSalesQuantity: null,
        isRepaired: null,
        isDelete: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      value1: "",
      value2: "",
    };
  },
  filters: {
    state1(string) {
      if (string == "0") {
        return "是";
      }
      if (string == "1") {
        return "否";
      }
      // if (string == "VFU") {
      //     return "VFU";
      // }
      // if (int == 2) { return "审批通过" };
    },
  },
  created() {
    this.getList();
  },
  methods: {
    changeTime() {
      // console.log(JSON.stringify(this.value2));
      let m1 = moment(this.value2[0]).format("YYYY-MM-DD");
      let m2 = moment(this.value2[1]).format("YYYY-MM-DD");
      // console.log(JSON.stringify(m1));
      // console.log(JSON.stringify(m2));
      this.queryParams.startDate = m1;
      this.queryParams.endDate = m2;
    },
    // 打开加载层
    openLoading1() {
      this.$modal.loading("正在加载数据，请稍候！");
    },
    handlerecoverAbnormal() {
      if (this.ids.length == 0) {
        this.$modal.msgError("请选择一条数据");
        return;
      }
      this.openLoading1();
      recoverAbnormal(this.ids).then((response) => {
        if (response.code == 200) {
          this.$modal.closeLoading();
          this.getList();
          this.$modal.msgSuccess(response.msg);
        }
      });
    },
    /** 查询达播异常订单列表 */
    getList() {
      this.loading = true;
      listBiAbnormalOrder(this.queryParams).then((response) => {
        this.BiAbnormalOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        exceptionOrderId: null,
        exceptionSubOrderId: null,
        orderSalesAmount: null,
        talentSalesAmount: null,
        orderSalesQuantity: null,
        talentSalesQuantity: null,
        isRepaired: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null,
        isDelete: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");

      this.queryParams = {};
      this.value2 = "";
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加达播异常订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBiAbnormalOrder(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改达播异常订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBiAbnormalOrder(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBiAbnormalOrder(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除达播异常订单编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBiAbnormalOrder(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "live/BiAbnormalOrder/export",
        {
          ...this.queryParams,
        },
        `BiAbnormalOrder_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
